package com.zmn.brs.task.listenter.engineer;

import com.alibaba.fastjson.JSONObject;
import com.zmn.brs.business.interfaces.engineer.EngineerUpaidBService;
import com.zmn.brs.common.constant.BrsMqConst;
import com.zmn.brs.common.enums.EventTypeEnum;
import com.zmn.manager.mq.annotation.AliyunMQHandler;
import com.zmn.manager.mq.annotation.AliyunMQListener;
import com.zmn.track.common.dto.trackwork.QueueTrackDataDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 类描述：跟单工程师收款未支付消息监听
 *
 * @author chongw
 * @since 2021/07/08 09:52
 */
@Slf4j
@Component
@AliyunMQListener(topic = "${spring.mq.topic.track}")
public class EngineerUpaidMessageQueueListener {

    final static String TAG = "TRACK跟单消息监听";

    @Resource
    EngineerUpaidBService engineerUpaidBService;

    @AliyunMQHandler(topic = "${spring.mq.topic.track}", tags = BrsMqConst.MESSAGE_TRACK_NODE_NOTICE)
    public void handler(String message) {
        log.info("[{}],接收到新的消息message,原始消息:{}", TAG, message);
        try {
            QueueTrackDataDTO queueTrackDataDTO = JSONObject.parseObject(message, QueueTrackDataDTO.class);
            //收款未支付金额执行
            Boolean flag = engineerUpaidBService.compute(EventTypeEnum.ENGINEER_UNPAID.getTypeId(), queueTrackDataDTO);
            if (flag) {
                log.info("[{}], 消息处理成功！！！", TAG);
                return;
            }
            log.error("[{}], 消息处理失败！！！，消息体:{}", TAG, message);
        }catch (Exception e){
            log.error("[{}], 消息处理异常！！！，消息体:{}，异常信息：{}", TAG, message, e);
        }
    }

}
